<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>Graph 3D animation moving dots</title>

    <style>
        body {font: 10pt arial;}
    </style>

    <script type="text/javascript" src="http://www.google.com/jsapi"></script>
    <script type="text/javascript" src="../graph3d.js"></script>

    <script type="text/javascript">
        var data = null;
        var graph = null;

        google.load("visualization", "1");

        // Set callback to run when API is loaded
        google.setOnLoadCallback(drawVisualization);

        // Called when the Visualization API is loaded.
        function drawVisualization() {
            // create the data table.
            data = new google.visualization.DataTable();
            data.addColumn('number', 'x');
            data.addColumn('number', 'y');
            data.addColumn('number', 'z');
            data.addColumn('number', 'color value');
            data.addColumn('number', 'time');

            // create some shortcuts to math functions
            var sin = Math.sin;
            var cos = Math.cos;
            var pi = Math.PI;

            // create the animation data
            var tmax = 2.0 * pi;
            var tstep = tmax / 75;
            var dotCount = 1;  // set this to 1, 2, 3, 4, ...
            for (var t = 0; t < tmax; t += tstep) {
                var tgroup = parseFloat(t.toFixed(2));
                var value = t;

                // a dot in the center
                data.addRow([0, 0, 0, value, tgroup]);

                // one or multiple dots moving around the center
                for (var dot = 0; dot < dotCount; dot++) {
                    var tdot = t + 2*pi * dot / dotCount;
                    data.addRow([sin(tdot),  cos(tdot), sin(tdot), value, tgroup]);
                    data.addRow([sin(tdot), -cos(tdot), sin(tdot + tmax*1/2), value, tgroup]);
                }
            }

            // specify options
            var options = {
                width:  "600px",
                height: "600px",
                style: "dot-color",
                showPerspective: true,
                showGrid: true,
                keepAspectRatio: true,
                verticalRatio: 1.0,
                animationInterval: 35, // milliseconds
                animationPreload: false,
                animationAutoStart: true,
                cameraPosition:
                {
                    horizontal: 2.7,
                    vertical: 0.0,
                    distance: 1.65
                }
            };

            // Instantiate our graph object.
            graph = new links.Graph3d(document.getElementById('mygraph'));

            // Draw our graph with the created data and options
            graph.draw(data, options);
        }
    </script>
</head>

<body>
<div id="mygraph"></div>

<div id="info"></div>
</body>
</html>
